<template>
  <div>
    <nav-bar class="detail-nav">
      <div slot="left" @click="backHome">
        <div class="backHome"></div>
      </div>
      <div slot="center">
        <span
          v-for="(item, index) in titles"
          :key="index"
          :class="{ active: index === currentIndex }"
          @click="clickItem(index)"
          >{{ item }}</span
        >
      </div>
      <div slot="right"></div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/NavBar/NavBar.vue";

export default {
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    clickItem(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    },
    backHome() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped>
.detail-nav > div:nth-child(2) > div {
  display: flex;
  justify-content: space-around;
}
.detail-nav > div:nth-child(2) > div > span {
  flex: 1;
  font-size: 15px;
}
.active {
  color: #ff8e96;
}
.backHome {
  margin: 14px auto;
  width: 13px;
  height: 13px;
  border-top: 3px solid #535353;
  border-left: 3px solid #535353;
  transform: rotate(-45deg);
}
</style>